package com.ming.transaction.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * @author: Chenming
 * @date 2023/5/9 17:50
 */

@Configuration
public class RabbitMQConfig {

    //交换机名称
    public static final String ITEM_EXCHANGE = "log_exchange";
    //队列名称
    public static final String ITEM_QUEUE = "log_queue";
    // 声明交换机
    @Bean("logExchange")
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange(ITEM_EXCHANGE).durable(true).build();
    }
    //声明队列
    @Bean("logQueue")
    public Queue itemQueue(){
        return  QueueBuilder.durable(ITEM_QUEUE).build();
    }
    // 绑定队列和交换机
    @Bean
    public Binding itemQueueExchange(@Qualifier("logQueue") Queue queue,
                                     @Qualifier("logExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("log.#").noargs();
    }

    //// 订单队列
    //public static final String ORDER_EXCHANGE = "order_exchange";
    //// 订单交换机名称
    //public static final String ORDER_QUEUE = "order_queue";
    //// 声明交换机
    //@Bean("orderExchange")
    //public Exchange orderExchange(){
    //    return ExchangeBuilder.topicExchange(ORDER_EXCHANGE).durable(true).build();
    //}
    ////声明队列
    //@Bean("orderQueue")
    //public Queue orderQueue(){
    //    return  QueueBuilder.durable(ORDER_QUEUE).build();
    //}
    //// 绑定队列和交换机
    //@Bean
    //public Binding orderQueueExchange(@Qualifier("orderQueue") Queue queue,
    //                                 @Qualifier("orderExchange") Exchange exchange){
    //    return BindingBuilder.bind(queue).to(exchange).with("order.#").noargs();
    //}


}
